import random

data = random.randint(1, 30)

# 定义商品
shop = [
    ["老干妈", 15],
    ["联想电脑", 3000]
]
# 购物车为空
mycar = []

# 账户余额
money = 30000

num0 = 0
# 老干妈7折
if data <= 10:
    num0 = 70 / 100
    print("**** 恭喜您抽到老干妈优惠7折券！****")
    i = 1
    while i >= 1:
        # 列表清单与输入
        for key, value in enumerate(shop):
            print(key, value)
        num1 = input("请输入您想买的商品号：/输入Q或q退出系统：")
        if num1 != "0" and num1 != "1" and num1 != "q" and num1 != "Q":
            print("输入有误，请重新输入！")
            continue
        elif num1 == "Q" or num1 == "q":
            print("**** 欢迎下次光临！****")
            exit(0)
        num2 = input("请输入您要买的数量：")
        num2 = int(num2)
        if num2 != int(num2):
            print("您输入有误，请重新输入")
            continue

        # 判断商品是否存在
        if num1.isdigit():
            num1 = int(num1)
        # 有老干妈券开始第一次购买商品
        if i == 1:
            # 判断余额是否充足
            if money < shop[num1][1]:
                print("余额不足")
            # 将商品拉入购物车
            else:
                # 第一次有券的老干妈
                if num1 == 0:
                    mycar.append([shop[num1], shop[num1][1] * num0 + shop[num1][1] * (num2 - 1)])
                    money = money - mycar[i - 1][1]
                    # for i in mycar:
                    #     print(mycar)
                    chose = input("**** 是否继续购买？ ”Y“ or ”N“ ****")
                    if chose != "Y" and chose != "y" and chose != "n" and chose != "N":
                        print("输入错误，请重新输入！")
                        continue
                    elif chose == "y" or chose == "Y":
                        i = i + 1
                        continue
                    elif chose == "n" or chose == "N":
                        print("**** 这是您的小票，请拿好！****")
                        print("**** 商品\t\t购买价格****")
                        list = []
                        for j in mycar:
                            list.append(j[1])
                            print("\t", j[0][0], "\t", float(j[1]))
                        print("所花费金额为", float(sum(list)))
                        print("**** 欢迎下次光临！****")
                        break
                    continue
                elif num1 == 1:
                    # 判断余额是否充足
                    if money < shop[num1][1]:
                        print("余额不足")
                    # 将商品拉入购物车
                    else:
                        mycar.append([shop[num1], shop[num1][1] * num2])
                        money = money - mycar[i - 1][1]
                        chose = input("**** 是否继续购买？ ”Y“ or ”N“ ****")
                        if chose != "Y" and chose != "y" and chose != "n" and chose != "N":
                            print("输入错误，请重新输入！")
                            continue
                        elif chose == "y" or chose == "Y":
                            continue
                        elif chose == "n" or chose == "N":
                            print("**** 这是您的小票，请拿好！****")
                            print("**** 商品\t\t购买价格 ****")
                            list = []
                            for j in mycar:
                                list.append(j[1])
                                print("\t", j[0][0], "\t", float(j[1]))
                            print("所花费金额为", float(sum(list)))
                            print("**** 欢迎下次光临！****")
                            break
                        continue
        # 有老干妈券，但用了
        elif i != 1:
            # 判断余额是否充足
            if money < shop[num1][1]:
                print("余额不足")
            # 将商品拉入购物车
            else:
                mycar.append([shop[num1], shop[num1][1] * num2])
                money = money - mycar[i - 1][1]
                chose = input("**** 是否继续购买？ ”Y“ or ”N“ ****")
                if chose != "Y" and chose != "y" and chose != "n" and chose != "N":
                    print("输入错误，请重新输入！")
                    continue
                elif chose == "y" or chose == "Y":
                    i = i + 1
                    continue
                elif chose == "n" or chose == "N":
                    print("**** 这是您的小票，请拿好！****")
                    print("**** 商品\t\t购买价格 ****")
                    list = []
                    for j in mycar:
                        list.append(j[1])
                        print("\t", j[0][0], "\t", float(j[1]))
                    print("所花费金额为", float(sum(list)))
                    print("**** 欢迎下次光临！****")
                    break
                continue
# 电脑1折
elif data > 10 and data <= 30:
    num0 = 10 / 100
    print("**** 恭喜您抽到联想电脑优惠1折券！****")
    i = 1
    while i >= 1:
        # 列表清单与输入
        for key, value in enumerate(shop):
            print(key, value)
        num1 = input("请输入您想买的商品号：/输入Q或q退出系统：")
        if num1 != "0" and num1 != "1" and num1 != "q" and num1 != "Q":
            print("输入有误，请重新输入！")
            continue
        elif num1 == "Q" or num1 == "q":
            print("**** 欢迎下次光临！****")
            exit(0)
        num2 = input("请输入您要买的数量：")
        num2 = int(num2)
        if num2 != int(num2):
            print("您输入有误，请重新输入")
            continue

        # 判断商品是否存在
        if num1.isdigit():
            num1 = int(num1)
        # 有电脑券开始第一次购买商品
        if i == 1:
            # 判断余额是否充足
            if money < shop[num1][1]:
                print("余额不足")
            # 将商品拉入购物车
            else:
                # 第一次有券的电脑券
                if num1 == 1:
                    mycar.append([shop[num1], shop[num1][1] * num0 + shop[num1][1] * (num2 - 1)])
                    money = money - mycar[i - 1][1]
                    chose = input("**** 是否继续购买？ ”Y“ or ”N“ ****")
                    if chose != "Y" and chose != "y" and chose != "n" and chose != "N":
                        print("输入错误，请重新输入！")
                        continue
                    elif chose == "y" or chose == "Y":
                        i = i + 1
                        continue
                    elif chose == "n" or chose == "N":
                        print("**** 这是您的小票，请拿好！****")
                        print("**** 商品\t\t购买价格 ****")
                        list = []
                        for j in mycar:
                            list.append(j[1])
                            print("\t", j[0][0], "\t", float(j[1]))
                        print("所花费金额为", float(sum(list)))
                        print("**** 欢迎下次光临！****")
                        break
                    continue
                elif num1 == 0:
                    # 判断余额是否充足
                    if money < shop[num1][1]:
                        print("余额不足")
                    # 将商品拉入购物车
                    else:
                        mycar.append([shop[num1], shop[num1][1] * num2])
                        money = money - mycar[i - 1][1]
                        chose = input("**** 是否继续购买？ ”Y“ or ”N“ ****")
                        if chose != "Y" and chose != "y" and chose != "n" and chose != "N":
                            print("输入错误，请重新输入！")
                            continue
                        elif chose == "y" or chose == "Y":
                            continue
                        elif chose == "n" or chose == "N":
                            print("**** 这是您的小票，请拿好！****")
                            print("**** 商品\t\t购买价格 ****")
                            list = []
                            for j in mycar:
                                list.append(j[1])
                                print("\t", j[0][0], "\t", float(j[1]))
                            print("所花费金额为", float(sum(list)))
                            print("**** 欢迎下次光临！****")
                            break
                        continue
        # 有电脑券，但用了
        elif i != 1:
            # 判断余额是否充足
            if money < shop[num1][1]:
                print("余额不足")
            # 将商品拉入购物车
            else:
                mycar.append([shop[num1], shop[num1][1] * num2])
                money = money - mycar[i - 1][1]
                chose = input("**** 是否继续购买？ ”Y“ or ”N“ ****")
                if chose != "Y" and chose != "y" and chose != "n" and chose != "N":
                    print("输入错误，请重新输入！")
                    continue
                elif chose == "y" or chose == "Y":
                    i = i + 1
                    continue
                elif chose == "n" or chose == "N":
                    print("**** 这是您的小票，请拿好！****")
                    print("**** 商品\t\t购买价格 ****")
                    list = []
                    for j in mycar:
                        list.append(j[1])
                        print("\t", j[0][0], "\t", float(j[1]))
                    print("所花费金额为", float(sum(list)))
                    print("**** 欢迎下次光临！****")
                    break
                continue
